<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/all.min.css" integrity="sha256-mUZM63G8m73Mcidfrv5E+Y61y7a12O5mW4ezU3bxqW4=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"anynone.gitee.io","root":"/","images":"/images","scheme":"Pisces","darkmode":true,"version":"8.7.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>
<meta name="description" content="重启网络服务 1systemctl restart networking 查看全部网卡 1ifconfig -a 修改ip地址 12# ifconfig 网卡名称 ip地址ifconfig eth0 192.168.1.100 向主机发送ICMP报文 12# 想192.168.1.100发送3次报文ping -c 192.168.1.100 探测局域网ip 12# ping -b -c 局域网广">
<meta property="og:type" content="article">
<meta property="og:title" content="linux网络相关命令(ubuntu)">
<meta property="og:url" content="https://anynone.gitee.io/2022/04/01/linux-command-network/index.html">
<meta property="og:site_name" content="anynone">
<meta property="og:description" content="重启网络服务 1systemctl restart networking 查看全部网卡 1ifconfig -a 修改ip地址 12# ifconfig 网卡名称 ip地址ifconfig eth0 192.168.1.100 向主机发送ICMP报文 12# 想192.168.1.100发送3次报文ping -c 192.168.1.100 探测局域网ip 12# ping -b -c 局域网广">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-04-01T15:29:10.000Z">
<meta property="article:modified_time" content="2022-09-09T00:09:56.415Z">
<meta property="article:author" content="山丘之王">
<meta property="article:tag" content="linux,网络,route">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://anynone.gitee.io/2022/04/01/linux-command-network/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://anynone.gitee.io/2022/04/01/linux-command-network/","path":"2022/04/01/linux-command-network/","title":"linux网络相关命令(ubuntu)"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>linux网络相关命令(ubuntu) | anynone</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">anynone</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <img src="/images/head.jpg">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">山丘之王</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">22</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/anynone" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;anynone" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://anynone.gitee.io/2022/04/01/linux-command-network/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="山丘之王">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="anynone">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          linux网络相关命令(ubuntu)
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-04-01 23:29:10" itemprop="dateCreated datePublished" datetime="2022-04-01T23:29:10+08:00">2022-04-01</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-09-09 08:09:56" itemprop="dateModified" datetime="2022-09-09T08:09:56+08:00">2022-09-09</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <ul>
<li><p>重启网络服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart networking</span><br></pre></td></tr></table></figure></li>
<li><p>查看全部网卡</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ifconfig -a</span><br></pre></td></tr></table></figure></li>
<li><p>修改ip地址</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ifconfig 网卡名称 ip地址</span></span><br><span class="line">ifconfig eth0 192.168.1.100</span><br></pre></td></tr></table></figure></li>
<li><p>向主机发送ICMP报文</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 想192.168.1.100发送3次报文</span></span><br><span class="line">ping -c 192.168.1.100</span><br></pre></td></tr></table></figure></li>
<li><p>探测局域网ip</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ping -b -c 局域网广播地址</span></span><br><span class="line">ping -b -c 192.168.1.255</span><br></pre></td></tr></table></figure></li>
<li><p>查询本地开启的端口</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">netstat -tupna</span><br></pre></td></tr></table></figure>

<p><strong>注意下State信息的意义</strong></p>
<ul>
<li>LISTEN: 监听状态</li>
<li>ESTABLISHED: 已经建立的连接</li>
<li>SYN_SENT: 主动发起连接的数据包</li>
<li>SYN_RECV: 接收到主动连接的数据包</li>
<li>FIN_WAIT1： 正在中断的连接</li>
<li>FIN_WAIT2: 已经中断，正在等待对方主机确认断开</li>
<li>TIME_WAIT: 连接已经中断，套接字资源在等待被释放</li>
<li>CLOSED: 套接字已关闭，没有被占用</li>
</ul>
</li>
<li><p>查看路由表</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># netstat命令查看</span></span><br><span class="line">netstat -rn</span><br><span class="line"><span class="comment"># route命令查看</span></span><br><span class="line">route -v</span><br><span class="line"><span class="comment"># ip命令查看</span></span><br><span class="line">ip route show</span><br></pre></td></tr></table></figure></li>
<li><p>查看访问某个ip的路由信息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ip route get ip地址</span></span><br><span class="line">ip route get 192.168.1.100</span><br></pre></td></tr></table></figure></li>
<li><p>指定/添加某个ip使用的网卡</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># route add -host 目的IP地址 dev 网卡名称</span></span><br><span class="line"><span class="comment"># 示例：通过eth2访问31.102这个ip</span></span><br><span class="line">route add -host 192.168.31.102 dev eth2</span><br></pre></td></tr></table></figure></li>
<li><p>指定某个ip访问时经过的网关</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#route add -host 目的ip地址 gw 网关地址</span></span><br><span class="line"><span class="comment"># 示例： 指定31.102访问时经过200.1这个网关</span></span><br><span class="line">route add -host 192.168.31.102 gw 192.168.200.1 </span><br></pre></td></tr></table></figure></li>
<li><p>删除一条路由</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># route del 路由表配置</span></span><br><span class="line"><span class="comment"># 删除 192.168.31.102 通过eth2访问的路由</span></span><br><span class="line">route del -host 192.168.31.102 dev eth2</span><br></pre></td></tr></table></figure></li>
<li><p>添加网段经过的网关</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># route add -net 目的网段 netmask 子网掩码 gw 要经过的网关</span></span><br><span class="line">route add -net 192.168.31.0 netmask 255.255.255.0 gw 192.168.200.1</span><br><span class="line"><span class="comment"># 另一种简略写法</span></span><br><span class="line">route add -net 192.168.31.0/24 gw 192.168.200.1</span><br></pre></td></tr></table></figure></li>
<li><p>添加目的网段使用的网卡</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># route add -net 目的网段 netmask 子网掩码 dev 网卡名称</span></span><br><span class="line">route add -net 192.168.31.0 netmask 255.255.255.0 dev eth1</span><br><span class="line"><span class="comment"># 简写</span></span><br><span class="line">route add -net 192.168.31.0/24 dev eth1</span><br></pre></td></tr></table></figure>

<p><strong>注意，网卡相关想要永久存储路由，将上述路由相关命令写入到/etc/rc.local配置文件中</strong></p>
</li>
<li><p>向其他用户发送消息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># w命令获取终端号</span></span><br><span class="line"><span class="comment"># write 用户名 终端号</span></span><br><span class="line">write mick pts/3</span><br><span class="line"><span class="comment"># 回车输入按行发送消息，CTRL+D结束</span></span><br></pre></td></tr></table></figure></li>
<li><p>探测端口可用性</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># telnet ip地址 端口号</span></span><br><span class="line"><span class="comment"># 探测192.168.100.1 的22端口是否能够访问</span></span><br><span class="line">telnet 192.168.100.1 22</span><br></pre></td></tr></table></figure></li>
<li><p>解析域名</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 解析百度ip地址</span></span><br><span class="line">nslookup baidu.com</span><br><span class="line"><span class="comment"># 使用指定的8.8.8.8 DNS服务器解析baidu.com</span></span><br><span class="line">nslookup baidu.com 8.8.8.8</span><br><span class="line"><span class="comment"># 另一个命令解析baidu.com的解析信息</span></span><br><span class="line">dig baidu.com</span><br></pre></td></tr></table></figure></li>
</ul>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/linux-%E7%BD%91%E7%BB%9C-route/" rel="tag"># linux,网络,route</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2022/03/31/linux-ununual-command/" rel="prev" title="linux常用命令----mount和umount设备挂载">
                  <i class="fa fa-chevron-left"></i> linux常用命令----mount和umount设备挂载
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2022/04/07/qt-connect/" rel="next" title="qt信号和槽函数">
                  qt信号和槽函数 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2021 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">山丘之王</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  





  





</body>
</html>
